package jjn.carl.dp;

import java.util.Arrays;
import java.util.Scanner;

/**
 * @author Jiang Jining
 * @since 2023-08-20 23:33
 */
public class LeetCode322 {
    public int coinChange(int[] coins, int amount) {
        int[] dp = new int[amount + 1];
        Arrays.fill(dp, 10001);
        dp[0] = 0;
        for (int i = 0; i <= amount; i++) {
            for (int j = 0; j < coins.length; j++) {
                if (i >= coins[j]) {
                    dp[i] = Math.min(dp[i], dp[i - coins[j]] + 1);
                }
            }
        }
        return dp[amount] == 10001 ? -1 : dp[amount];
    }
    
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int coinNum = scanner.nextInt();
        int amount = scanner.nextInt();
        int[] coins = new int[coinNum];
        for (int i = 0; i < coinNum; i++) {
            coins[i] = scanner.nextInt();
        }
        int coinChange = new LeetCode322().coinChange(coins, amount);
        System.out.println(coinChange);
    }
}
